﻿/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
*/

package com.chasekernan.hxnova.componenteditor.details;

import com.chasekernan.hxnova.componenteditor.DetailsPanel;
import com.chasekernan.hxnova.core.components.BeamWeapon;
import org.aswing.JAdjuster;
import org.aswing.JCheckBox;
import com.chasekernan.hxnova.componenteditor.ComponentEditorPanel;

class BeamWeaponPanel extends DetailsPanel {
    private var powerInput : JAdjuster;
    private var rangeInput : JAdjuster;
    private var initiativeInput : JAdjuster;
    private var isSapper : JCheckBox;
    private var isGattling : JCheckBox;
    
    public function new() {
        super();
        
        powerInput = DetailsPanel.createIntAdjuster(1, 10000);
        rangeInput = DetailsPanel.createIntAdjuster(0, 10);
        initiativeInput = DetailsPanel.createIntAdjuster(0, 100);
        
        isSapper = new JCheckBox("Is Sapper?");
        isGattling = new JCheckBox("Is Gattling?");
        
        addRowHaxe(createLeftLabel("Power"), powerInput, null);
        addRowHaxe(createLeftLabel("Range"), rangeInput, null);
        addRowHaxe(createLeftLabel("Initiative"), initiativeInput, null);
        addSeparator();
        addRowHaxe(isSapper, null, null);
        addRowHaxe(isGattling, null, null);
        
        allInputs = [powerInput, rangeInput, initiativeInput, isSapper, isGattling];
    }
    
    public override function loadFromComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var beamWeapon = cast(ComponentEditorPanel.INSTANCE.editedComponent, BeamWeapon);
        
        powerInput.setValue(beamWeapon.power);
        rangeInput.setValue(beamWeapon.range);
        initiativeInput.setValue(beamWeapon.initiative);
        
        isSapper.setSelected(beamWeapon.isSapper);
        isGattling.setSelected(beamWeapon.isGattling);
    }
    
    public override function saveToComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var beamWeapon = cast(ComponentEditorPanel.INSTANCE.editedComponent, BeamWeapon);
        
        beamWeapon.power = powerInput.getValue();
        beamWeapon.range = rangeInput.getValue();
        beamWeapon.initiative = initiativeInput.getValue();
        
        beamWeapon.isSapper = isSapper.isSelected();
        beamWeapon.isGattling = isGattling.isSelected();
    }
}